package service

import (
	"github.com/gin-gonic/gin"
	"talentsystem/model"
	"github.com/astaxie/beego/orm"
)

func Feedback (c*gin.Context){
	var param model.Feedback
	if err:=c.Bind(&param);err!=nil {
		c.JSON(400, gin.H{
			"status": 400,
			"msg":    "参数格式不正确",
		})
		return
	}
	feedback:=new(model.Feedback)
	feedback.AccountId=param.AccountId
	feedback.Content=param.Content
	feedback.Type=param.Type
	feedback.Date=param.Date
	_,err:=orm.NewOrm().Insert(feedback)
	if err!=nil {
		c.JSON(500, gin.H{
			"status": 500,
			"msg":  "系统错误请刷新",
		})
		return
	}
	c.JSON(200, gin.H{
		"status": 200,
		"msg":    1,
	})
	return
}
func GetFeedback(c*gin.Context){
	var param model.GetAccountApplyJob
	if err:=c.Bind(&param);err!=nil {
		c.JSON(400, gin.H{
			"status": 400,
			"msg":    "参数格式不正确",
		})
		return
	}
	offset:=(param.Page-1)*param.Pagesize
	var feedback []model.Feedback
	_,err:=orm.NewOrm().QueryTable("feedback").Offset(offset).Limit(param.Pagesize).OrderBy("-id").All(&feedback)
	if err!=nil {
		c.JSON(500, gin.H{
			"status": 500,
			"msg":  "系统错误请刷新",
		})
		return
	}
	num,err:=orm.NewOrm().QueryTable("feedback").Count()
	if err!=nil {
		c.JSON(500, gin.H{
			"status": 500,
			"msg":  "系统错误请刷新",
		})
		return
	}
	c.JSON(200, gin.H{
		"status": 200,
		"data":  feedback,
		"total":num,
	})
	return
}